from flask import Flask
from models.models import db, UserAuth
from routes.routes import main_bp
from config import Config

app = Flask(__name__)
app.config.from_object(Config)
db.init_app(app)

# 注册蓝图
app.register_blueprint(main_bp)

if __name__ == '__main__':
    app.run(debug=True)

with app.app_context():
    # 检查表是否存在
    db.create_all()
    # 插入测试账号
    if not UserAuth.query.filter_by(username='admin1').first():
        db.session.add(UserAuth(username='admin1', password='adminpass', role='admin'))
    if not UserAuth.query.filter_by(username='customer1').first():
        db.session.add(UserAuth(username='customer1', password='custpass', role='customer'))
    db.session.commit() 